package
        edu.sctu.zhengsenwen.month201506.day20150616.network;


import java.io.BufferedReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;

/**
 * 应用URL类读取网络文件的实例
 * Created by user15 on 2015/6/17.
 */
public class ReadingURL {


    public static void main(String[] args)
            throws IOException {


        //创建URL类
        URL url = new URL
                ("http://java.sun.com/");

        //通过InputStreamReader建立BufferReader文件读入类

        BufferedReader input = new
                BufferedReader(new InputStreamReader
                (url.openStream()));

        //创建文件写出类，网页的内容写入文件java_sun_con.txt


        FileWriter output = new
                FileWriter("java_sun_com.txt");


        //通过循环把内容写进文件
        String inputLine;

        while((inputLine = input.readLine
                ()) != null){

            System.out.println(inputLine);

            output.write(inputLine+"\n");

        }

        output.flush();

        input.close();

        output.close();
    }


}
